import Vue from 'vue';
import Vuex from 'vuex';
import {
    ADD_COUNT,
    ADD_COUNT_SYNC
} from './mutation-types'

Vue.use(Vuex);


export const store = new Vuex.Store({
    state:{
        count:0
    },

    mutations:{
        [ADD_COUNT] (state) {
            state.count++;
        },

        [ADD_COUNT_SYNC] (state) {
            setTimeout(() => {
                state.count++;
            },1000)
        }
    },

    actions: {
        increment:({commit}) => commit('ADD_COUNT'),

        incrementSync:({commit}) => {
            return new Promise(resolve => {
                commit('ADD_COUNT_SYNC');
                resolve();
            })
        }
    }
});
